"use strict";

let ELayout = function () {
    let $body = $('body');
    let $aside = $('#aside');
    let asideMenu = null;

    let asideMenuOffCanvas;

    /**
     * 移动端模式header-topbar显示 & 隐藏
     */
    let initMobileHeaderToggle = function () {
        $body.on('click', '#header-mobile-toggle', function () {
            let $headerMobileToggle = $(this);
            if ($headerMobileToggle.hasClass('active')) {
                // 隐藏
                $body.removeClass(cssPrefix + 'header-topbar--mobile-on');
                $headerMobileToggle.removeClass('active');
            } else {
                // 显示
                $body.addClass(cssPrefix + 'header-topbar--mobile-on');
                $headerMobileToggle.addClass('active');
            }
        });
    };

    /**
     * 移动端模式侧边显示 & 隐藏
     */
    let initMobileAsideToggler = function () {
        // 移动端模式菜单的显示 & 隐藏
        asideMenuOffCanvas = new EOffCanvas('#aside', {
            baseClass: 'e-aside',
            overlay: true,
            closeBy: '#ef_aside_close_btn',
            toggleBy: {
                // 用于切换显示 & 隐藏的按钮选择器
                target: '#header-mobile-aside-toggler',
                // 当显示时按钮上面添加的class
                state: 'active'
            }
        });
    };

    /**
     * pc模式切换菜单展开 & 收起
     */
    let initAsideToggler = function () {
        $body.on('click', '#aside-toggler', function () {
            let $asideToggler = $(this);
            if ($asideToggler.hasClass('active')) {
                $asideToggler.removeClass('active');
                // 还原
                $body.removeClass(cssPrefix + 'aside--minimize ' + cssPrefix + 'aside--minimize-hover');
            } else {
                $asideToggler.addClass('active');
                // 收起
                $body.addClass(cssPrefix + 'aside--minimize');
            }
        });

        // 当收起时，鼠标enter展开
        let insideTm;
        let outsideTm;

        $aside.mouseenter(function (e) {
            e.preventDefault();
            if (!EUtil.isInResponsiveRange('desktop')) {
                return;
            }
            // 清除消失定时器
            if (outsideTm) {
                clearTimeout(outsideTm);
                outsideTm = null;
            }

            insideTm = setTimeout(function () {
                if ($body.hasClass('e-aside--minimize')) {
                    $body.removeClass('e-aside--minimize');

                    // Minimizing class
                    $body.addClass('e-aside--minimizing');

                    EUtil.transitionEnd($body[0], function () {
                        $body.removeClass('e-aside--minimizing');
                    });

                    // Hover class
                    $body.addClass('e-aside--minimize-hover');
                    // asideMenu.scrollUpdate();
                    // asideMenu.scrollTop();
                }
            }, 50);
        });

        $aside.mouseleave(function (e) {
            e.preventDefault();

            if (!EUtil.isInResponsiveRange('desktop')) {
                return;
            }

            if (insideTm) {
                clearTimeout(insideTm);
                insideTm = null;
            }

            outsideTm = setTimeout(function () {
                if ($body.hasClass('e-aside--minimize-hover')) {
                    $body.removeClass('e-aside--minimize-hover');
                    $body.addClass('e-aside--minimize');

                    // Minimizing class
                    $body.addClass('e-aside--minimizing');
                    EUtil.transitionEnd($body[0], function () {
                        $body.removeClass('e-aside--minimizing');
                    });
                    // Hover class
                    // asideMenu.scrollUpdate();
                    // asideMenu.scrollTop();
                }
            }, 100);
        });
    };
    /**
     * 初始化侧边菜单
     */
    let initAsideMenu = function () {
        let $menu = $('#aside-menu');

        asideMenu = new EMenu('#aside-menu', {
            // 滚动条
            scroll: {
                height: function () {
                    let height;

                    if (EUtil.isInResponsiveRange('desktop')) {
                        height = parseInt(EUtil.getViewPort().height) - parseInt($('#aside-brand').height());
                    } else {
                        height = parseInt(EUtil.getViewPort().height);
                    }

                    height = height - (parseInt($menu.css('margin-top').replace('px', '')) + parseInt($menu.css('margin-bottom').replace('px', '')));

                    return height;
                }
            },
            accordion: {
                expandMultiple: false // 是否启用打开多个子菜单
            }
        });
    };
    /**
     * 全屏 & 取消全屏
     */
    let initFullScreen = function () {
        /**
         * 全屏
         *
         * @param element {object} 要全屏的元素
         */
        function launchFullScreen(element) {
            if (element.requestFullscreen) {
                element.requestFullscreen();
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            } else if (element.webkitRequestFullscreen) {
                element.webkitRequestFullscreen();
            } else if (element.msRequestFullscreen) {
                element.msRequestFullscreen();
            }
        }

        /**
         * 退出全屏
         */
        function exitFullscreen() {
            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.webkitExitFullscreen) {
                document.webkitExitFullscreen();
            }
        }

        let icon = {
            full: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <polygon id="Bound" points="0 0 24 0 24 24 0 24"/>\n' +
                '        <path d="M6,18 L9,18 C9.66666667,18.1143819 10,18.4477153 10,19 C10,19.5522847 9.66666667,19.8856181 9,20 L4,20 L4,15 C4,14.3333333 4.33333333,14 5,14 C5.66666667,14 6,14.3333333 6,15 L6,18 Z M18,18 L18,15 C18.1143819,14.3333333 18.4477153,14 19,14 C19.5522847,14 19.8856181,14.3333333 20,15 L20,20 L15,20 C14.3333333,20 14,19.6666667 14,19 C14,18.3333333 14.3333333,18 15,18 L18,18 Z M18,6 L15,6 C14.3333333,5.88561808 14,5.55228475 14,5 C14,4.44771525 14.3333333,4.11438192 15,4 L20,4 L20,9 C20,9.66666667 19.6666667,10 19,10 C18.3333333,10 18,9.66666667 18,9 L18,6 Z M6,6 L6,9 C5.88561808,9.66666667 5.55228475,10 5,10 C4.44771525,10 4.11438192,9.66666667 4,9 L4,4 L9,4 C9.66666667,4 10,4.33333333 10,5 C10,5.66666667 9.66666667,6 9,6 L6,6 Z" id="Combined-Shape" fill="#000000" fill-rule="nonzero"/>\n' +
                '    </g>\n' +
                '</svg>',
            cancel: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <polygon id="Bound" points="0 0 24 0 24 24 0 24"/>\n' +
                '        <path d="M10,14 L5,14 C4.33333333,13.8856181 4,13.5522847 4,13 C4,12.4477153 4.33333333,12.1143819 5,12 L12,12 L12,19 C12,19.6666667 11.6666667,20 11,20 C10.3333333,20 10,19.6666667 10,19 L10,14 Z M15,9 L20,9 C20.6666667,9.11438192 21,9.44771525 21,10 C21,10.5522847 20.6666667,10.8856181 20,11 L13,11 L13,4 C13,3.33333333 13.3333333,3 14,3 C14.6666667,3 15,3.33333333 15,4 L15,9 Z" id="Combined-Shape" fill="#000000" fill-rule="nonzero"/>\n' +
                '        <path d="M3.87867966,18.7071068 L6.70710678,15.8786797 C7.09763107,15.4881554 7.73079605,15.4881554 8.12132034,15.8786797 C8.51184464,16.2692039 8.51184464,16.9023689 8.12132034,17.2928932 L5.29289322,20.1213203 C4.90236893,20.5118446 4.26920395,20.5118446 3.87867966,20.1213203 C3.48815536,19.7307961 3.48815536,19.0976311 3.87867966,18.7071068 Z M16.8786797,5.70710678 L19.7071068,2.87867966 C20.0976311,2.48815536 20.7307961,2.48815536 21.1213203,2.87867966 C21.5118446,3.26920395 21.5118446,3.90236893 21.1213203,4.29289322 L18.2928932,7.12132034 C17.9023689,7.51184464 17.2692039,7.51184464 16.8786797,7.12132034 C16.4881554,6.73079605 16.4881554,6.09763107 16.8786797,5.70710678 Z" id="Combined-Shape" fill="#000000" opacity="0.3"/>\n' +
                '    </g>\n' +
                '</svg>'
        };
        $('#full-screen').click(function () {
            let isFullScreen = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement
            if (isFullScreen) {
                $(this).find('.e-header-topbar-icon').html(icon.full);
                exitFullscreen();
            } else {
                $(this).find('.e-header-topbar-icon').html(icon.cancel);
                launchFullScreen(document.documentElement);
            }
        });
    };
    /**
     * 回到顶部
     */
    let initScrollTop = function () {
        /**
         * 处理回到顶部按钮显示/隐藏
         */
        let handle = function(){
            let pos = window.pageYOffset;
            if (pos > 300) {
                $body.addClass('e-scroll-top--on');
            } else {
                $body.removeClass('e-scroll-top--on');
            }
        };
        // 窗口滚动事件
        if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
            window.addEventListener('touchend', function() {
                handle();
            });

            window.addEventListener('touchcancel', function() {
                handle();
            });

            window.addEventListener('touchleave', function() {
                handle();
            });
        } else {
            window.addEventListener('scroll', function() {
                handle();
            });
        }
        // 绑定回到顶部事件
        $('#scroll-top').click(function () {
            EUtil.scrollTo('html,body', 0, 500);
        });
    };

    /**
     * 菜单回调
     */
    let menuCallback = function () {
        /**
         * 批量关闭标签页
         *
         * @param element {object} 标签页
         * @param type {string|null} closeOtherTabs/closeAllTabs/closeLeftTabs/closeRightTabs
         */
        let batchCloseTabs = function (element, type) {
            let $currentLi = $(element).parent();
            let $tabs = null;
            switch (type) {
                case 'closeOtherTabs':
                    // 获取除当前选中标签页以外的所有标签页
                    $currentLi.addClass('current-chose');
                    $tabs = $currentLi.parent().children(':not(.current-chose)');
                    $currentLi.removeClass('current-chose');
                    break;
                case 'closeAllTabs':
                    $tabs = $currentLi.parent().children();
                    break;
                case 'closeLeftTabs':
                    $tabs = $currentLi.prevAll();
                    break;
                case 'closeRightTabs':
                    $tabs = $currentLi.nextAll();
                    break;
                default:
                    // 默认关闭当前
                    $tabs = $currentLi;
            }
            $tabs.find('.tab-close').click();
            tabPage.toActiveTab();
        };

        /**
         * 刷新当前
         *
         * @param element {object} 标签页
         * @param key {string} 菜单key
         * @param opt {object} option
         */
        let refreshCurrentTabs = function (element, key, opt) {
            tabPage.refresh($(element).data('url'));
        };
        /**
         * 在新页面打开
         *
         * @param element {object} 标签页
         * @param key {string} 菜单key
         * @param opt {object} option
         */
        let cardingOnTheNewTab = function (element, key, opt) {
            window.open($(element).data('url'));
        };

        return {
            /**
             * 关闭当前
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            closeCurrentTab: function (key, opt) {
                batchCloseTabs(this, null);
            },
            /**
             * 关闭其他
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            closeOtherTabs: function (key, opt) {
                batchCloseTabs(this, 'closeOtherTabs');
            },
            /**
             * 关闭全部
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            closeAllTabs: function (key, opt) {
                batchCloseTabs(this, 'closeAllTabs');
            },
            /**
             * 关闭左边
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            closeLeftTabs: function (key, opt) {
                batchCloseTabs(this, 'closeLeftTabs');
            },
            /**
             * 关闭右边
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            closeRightTabs: function (key, opt) {
                batchCloseTabs(this, 'closeRightTabs');
            },
            /**
             * 刷新当前
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            refreshCurrentTabs: function (key, opt) {
                refreshCurrentTabs(this, key, opt)
            },
            /**
             * 在新标签页打开
             *
             * @param key {string} 菜单key
             * @param opt {object} option
             */
            cardingOnTheNewTab: function (key, opt) {
                cardingOnTheNewTab(this, key, opt);
            }
        }
    }();

    /**
     * 初始化标签页右键菜单
     */
    let initTabsRightMenu = function () {
        // 右键菜单绑定元素
        let defaultSelector = '.tab-page .con-tabs a.tab';
        /**
         * 菜单节点图标
         */
        let icon = {
            close: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <g id="Group" transform="translate(12.000000, 12.000000) rotate(-45.000000) translate(-12.000000, -12.000000) translate(4.000000, 4.000000)" fill="#000000">\n' +
                '            <rect id="Rectangle-185" x="0" y="7" width="16" height="2" rx="1"/>\n' +
                '            <rect id="Rectangle-185-Copy" opacity="0.3" transform="translate(8.000000, 8.000000) rotate(-270.000000) translate(-8.000000, -8.000000) " x="0" y="7" width="16" height="2" rx="1"/>\n' +
                '        </g>\n' +
                '    </g>\n' +
                '</svg>',
            left: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <polygon id="Shape" points="0 0 24 0 24 24 0 24"/>\n' +
                '        <rect id="Rectangle" fill="#000000" opacity="0.3" transform="translate(14.000000, 12.000000) scale(-1, 1) rotate(-90.000000) translate(-14.000000, -12.000000) " x="13" y="5" width="2" height="14" rx="1"/>\n' +
                '        <rect id="Rectangle-199-Copy" fill="#000000" opacity="0.3" x="3" y="3" width="2" height="18" rx="1"/>\n' +
                '        <path d="M5.7071045,15.7071045 C5.3165802,16.0976288 4.68341522,16.0976288 4.29289093,15.7071045 C3.90236664,15.3165802 3.90236664,14.6834152 4.29289093,14.2928909 L10.2928909,8.29289093 C10.6714699,7.914312 11.2810563,7.90106637 11.6757223,8.26284357 L17.6757223,13.7628436 C18.0828413,14.136036 18.1103443,14.7686034 17.7371519,15.1757223 C17.3639594,15.5828413 16.7313921,15.6103443 16.3242731,15.2371519 L11.0300735,10.3841355 L5.7071045,15.7071045 Z" id="Path-94" fill="#000000" fill-rule="nonzero" transform="translate(11.000001, 11.999997) scale(-1, -1) rotate(90.000000) translate(-11.000001, -11.999997) "/>\n' +
                '    </g>\n' +
                '</svg>',
            right: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <polygon id="Shape" points="0 0 24 0 24 24 0 24"/>\n' +
                '        <rect id="Rectangle" fill="#000000" opacity="0.3" transform="translate(14.000000, 12.000000) rotate(-90.000000) translate(-14.000000, -12.000000) " x="13" y="5" width="2" height="14" rx="1"/>\n' +
                '        <rect id="Rectangle-199-Copy" fill="#000000" opacity="0.3" x="3" y="3" width="2" height="18" rx="1"/>\n' +
                '        <path d="M11.7071032,15.7071045 C11.3165789,16.0976288 10.6834139,16.0976288 10.2928896,15.7071045 C9.90236532,15.3165802 9.90236532,14.6834152 10.2928896,14.2928909 L16.2928896,8.29289093 C16.6714686,7.914312 17.281055,7.90106637 17.675721,8.26284357 L23.675721,13.7628436 C24.08284,14.136036 24.1103429,14.7686034 23.7371505,15.1757223 C23.3639581,15.5828413 22.7313908,15.6103443 22.3242718,15.2371519 L17.0300721,10.3841355 L11.7071032,15.7071045 Z" id="Path-94" fill="#000000" fill-rule="nonzero" transform="translate(16.999999, 11.999997) scale(1, -1) rotate(90.000000) translate(-16.999999, -11.999997) "/>\n' +
                '    </g>\n' +
                '</svg>',
            refresh: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <rect id="bound" x="0" y="0" width="24" height="24"/>\n' +
                '        <path d="M8.43296491,7.17429118 L9.40782327,7.85689436 C9.49616631,7.91875282 9.56214077,8.00751728 9.5959027,8.10994332 C9.68235021,8.37220548 9.53982427,8.65489052 9.27756211,8.74133803 L5.89079566,9.85769242 C5.84469033,9.87288977 5.79661753,9.8812917 5.74809064,9.88263369 C5.4720538,9.8902674 5.24209339,9.67268366 5.23445968,9.39664682 L5.13610134,5.83998177 C5.13313425,5.73269078 5.16477113,5.62729274 5.22633424,5.53937151 C5.384723,5.31316892 5.69649589,5.25819495 5.92269848,5.4165837 L6.72910242,5.98123382 C8.16546398,4.72182424 10.0239806,4 12,4 C16.418278,4 20,7.581722 20,12 C20,16.418278 16.418278,20 12,20 C7.581722,20 4,16.418278 4,12 L6,12 C6,15.3137085 8.6862915,18 12,18 C15.3137085,18 18,15.3137085 18,12 C18,8.6862915 15.3137085,6 12,6 C10.6885336,6 9.44767246,6.42282109 8.43296491,7.17429118 Z" id="Combined-Shape" fill="#000000" fill-rule="nonzero"/>\n' +
                '    </g>\n' +
                '</svg>',
            open: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="e-svg-icon">\n' +
                '    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n' +
                '        <rect id="bound" x="0" y="0" width="24" height="24"/>\n' +
                '        <path d="M10.9,2 C11.4522847,2 11.9,2.44771525 11.9,3 C11.9,3.55228475 11.4522847,4 10.9,4 L6,4 C4.8954305,4 4,4.8954305 4,6 L4,18 C4,19.1045695 4.8954305,20 6,20 L18,20 C19.1045695,20 20,19.1045695 20,18 L20,16 C20,15.4477153 20.4477153,15 21,15 C21.5522847,15 22,15.4477153 22,16 L22,18 C22,20.209139 20.209139,22 18,22 L6,22 C3.790861,22 2,20.209139 2,18 L2,6 C2,3.790861 3.790861,2 6,2 L10.9,2 Z" id="Path-57" fill="#000000" fill-rule="nonzero" opacity="0.3"/>\n' +
                '        <path d="M24.0690576,13.8973499 C24.0690576,13.1346331 24.2324969,10.1246259 21.8580869,7.73659596 C20.2600137,6.12944276 17.8683518,5.85068794 15.0081639,5.72356847 L15.0081639,1.83791555 C15.0081639,1.42370199 14.6723775,1.08791555 14.2581639,1.08791555 C14.0718537,1.08791555 13.892213,1.15726043 13.7542266,1.28244533 L7.24606818,7.18681951 C6.93929045,7.46513642 6.9162184,7.93944934 7.1945353,8.24622707 C7.20914339,8.26232899 7.22444472,8.27778811 7.24039592,8.29256062 L13.7485543,14.3198102 C14.0524605,14.6012598 14.5269852,14.5830551 14.8084348,14.2791489 C14.9368329,14.140506 15.0081639,13.9585047 15.0081639,13.7695393 L15.0081639,9.90761477 C16.8241562,9.95755456 18.1177196,10.0730665 19.2929978,10.4469645 C20.9778605,10.9829796 22.2816185,12.4994368 23.2042718,14.996336 L23.2043032,14.9963244 C23.313119,15.2908036 23.5938372,15.4863432 23.9077781,15.4863432 L24.0735976,15.4863432 C24.0735976,15.0278051 24.0690576,14.3014082 24.0690576,13.8973499 Z" id="Shape" fill="#000000" fill-rule="nonzero" transform="translate(15.536799, 8.287129) scale(-1, 1) translate(-15.536799, -8.287129) "/>\n' +
                '    </g>\n' +
                '</svg>'
        };
        /**
         * 菜单节点
         */
        let items = {
            closeCurrentTab: {
                name: '关闭当前',
                icon: icon.close,
                type: 'format',
                disabled: checkMenu,
                callback: menuCallback.closeCurrentTab
            },
            closeOtherTabs: {
                name: '关闭其他',
                icon: icon.close,
                type: 'format',
                disabled: checkMenu,
                callback: menuCallback.closeOtherTabs
            },
            closeLeftTabs: {
                name: '关闭左侧',
                icon: icon.left,
                type: 'format',
                disabled: checkMenu,
                callback: menuCallback.closeLeftTabs
            },
            closeRightTabs: {
                name: '关闭右侧',
                icon: icon.right,
                type: 'format',
                disabled: checkMenu,
                callback: menuCallback.closeRightTabs
            },
            closeAllTabs: {
                name: '全部关闭',
                icon: icon.close,
                type: 'format',
                disabled: checkMenu,
                callback: menuCallback.closeAllTabs
            },
            sep1: '---------',
            refreshCurrentTabs: {
                name: '刷新页面',
                icon: icon.refresh,
                type: 'format',
                callback: menuCallback.refreshCurrentTabs
            },
            cardingOnTheNewTab: {
                name: '在新标签页打开',
                icon: icon.open,
                type: 'format',
                callback: menuCallback.cardingOnTheNewTab
            }
        };

        /**
         * 检查标签页是否可关闭
         *
         * @param $tab {object} 标签页
         * @return {true/false}
         */
        function checkCanClose($tab) {
            return $tab.find('.tab-close').length;
        }

        /**
         * 检查菜单节点是否 disabled
         *
         * @param key {string} 菜单节点key
         */
        function checkMenu(key) {
            let $currentLi = $(this).parent();
            let canClose = false;
            if ('closeCurrentTab' === key) {
                let tabClose = $(this).find('.tab-close');
                return !tabClose.length;
            } else if ('closeRightTabs' === key || 'closeLeftTabs' === key) {
                // 往左/右一个一个查找标签页是否可关闭,如遇到可关闭的则返回false
                let hasRightTab = true;
                let isCloseRightTabs = 'closeRightTabs' === key;
                while (hasRightTab) {
                    let next = null;
                    isCloseRightTabs ? next = $currentLi.next() : next = $currentLi.prev();
                    $currentLi = next;
                    if (!next.length) {
                        hasRightTab = false;
                    }
                    if (checkCanClose(next)) {
                        return false;
                    }
                }
                return true;
            } else if ('closeOtherTabs' === key || 'closeAllTabs' === key) {
                let isCloseOtherTabs = 'closeOtherTabs' === key;
                if (isCloseOtherTabs) {
                    // 如果是关闭其他,排除当前选中tab
                    $currentLi.addClass('current-chose');
                }
                let $tabs = $currentLi.parent().children(':not(.current-chose)');
                if (isCloseOtherTabs) {
                    $currentLi.removeClass('current-chose');
                }
                $($tabs).each(function (index, li) {
                    // 可以关闭
                    if (checkCanClose($(li))) {
                        canClose = true;
                        return;
                    }
                });
                return !canClose;
            }
            return false;
        }

        /**
         * 菜单节点格式化
         *
         * @param item {object} 节点属性
         * @param opt {object} 菜单属性
         * @param root
         */
        $.contextMenu.types.format = function (item, opt, root) {
            $('<a class="dropdown-item" href="#">' + item.icon + item.name + '</a>').appendTo(this);
        };

        $.contextMenu({
            selector: defaultSelector,
            items: items,
            classNames: {
                // 自定义菜单节点class
                hover: '-hover',
                visible: '-visible'
            }
        });
    };

    return {
        initHeader: function () {
            // 移动端模式header-topbar显示 & 隐藏
            initMobileHeaderToggle();
            // 全屏
            initFullScreen();
            // 初始化标签页
            EApp.initTabs();
            // 初始化标签页右键菜单
            initTabsRightMenu();
        },
        initAside: function () {
            // 左侧边
            initMobileAsideToggler();
            // pc模式切换菜单展开 & 收起
            initAsideToggler();
            // 初始化侧边菜单
            initAsideMenu();
        },
        // 初始化
        init: function () {
            if ($body.hasClass('e-root-page')) {
                ELayout.initHeader();
                ELayout.initAside();
            }
            initScrollTop();
        },
        /**
         * 获取侧边菜单对象
         *
         * @returns {*}
         */
        getAsideMenu: function () {
            return asideMenu;
        }
    }
}();
// 初始化
$(document).ready(function () {
    ELayout.init();
});


